/**
 * @author : zzr
 * @description :
 * @date :
 */

class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit{

}
class Fork {

}
class Message2<T> {
    private T message;

    public T getMessage() {
        return message;
    }

    public void setMessage(T message) {
        this.message = message;
    }
}
public class Test2 {
    public static void main(String[] args) {
        Message2<Apple> message2 = new Message2<>();
        message2.setMessage(new Apple());
        fun(message2);

        Message2<Fruit> message21 = new Message2<>();
        message21.setMessage(new Fruit());
        fun(message21);

        Message2<Fork> message22 = new Message2<>();
        message22.setMessage(new Fork());
//        fun(message22); //err
    }

    //此处使用通配符“？”描述的是fun方法中可以接收任意类型， ? extends Food 表明能接收的类型
    //Food本身，或者是Food的子类
    private static void fun(Message2<? extends Food> message2) {
        System.out.println(message2.getMessage());
    }
}
